Hallo vba-profis :)
ich habe ein problem:
Ich möchte einen Datensatz in access ändern. der unten stehende code ändert auch etwas und zwar nur den namen in -1 oder 0. ich weiß beim besten willen nicht warum.
Sub aendern_ma()
Dim conn As New ADODB.Connection
Dim rs As ADODB.Recordset
Dim db_name As String
Dim suchPara As String
Dim i As Integer
Dim j As Integer
Dim statement As String
db_name = ThisWorkbook.Path + "\" + "FestnetzDB.mdb"
tbl = ThisWorkbook.Sheets("DMS").cboxTbl.Value
tbl = Right(tbl, Len(tbl) - InStrRev(tbl, " "))
With ActiveWorkbook.Sheets("DMS")
For i = 3 To 30
If .Cells(3, i).Value <> "" And .Cells(4, i).Value <> "" And .Cells(3, i).Value <> "ID" Then
suchPara = suchPara & .Cells(3, i).Value & " "
If .Cells(4, i).Value <> "" Then
suchPara = suchPara & "= '" & .Cells(4, i).Value & "' AND "
End If
End If
Next
End With
suchPara = Left(suchPara, Len(suchPara) - 5)
conn.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & db_name & ";" & _
"Persist Security Info=False"
conn.Open
statement = "UPDATE " & tbl & " SET " & suchPara & " WHERE ID = " & ThisWorkbook.Sheets("DMS").Range("C4") & ";"
MsgBox statement
test.tbTest.Text = statement
test.Show
conn.Execute statement, , adCmdText
' Close the connection.
conn.Close
End Sub
Dies ist der zusammengebaute SQL-Befehl in der variable statement. alle spalten sind vom typ string außer die ID, mit der ich ja den datensatz bestimmt welcher geändert werden soll(soll und darf natürlich nciht geändert werden.
UPDATE ma SET name = 'Nadine' AND nachname = 'Jane' AND a_kennung = 'A120219910' AND email = 'kalmd' AND c_kennung = 'C20112008' AND
ma_nr = '11123' AND vp_nr = '923423423' AND vo_nr = 'JDHS' AND segment = 'HSDA' AND teamleiter = 'Sebastian_Klotten' AND rechte = '3' WHERE ID = 1;
könnt iihr mir bitte helfen??
|